package com.xiaolong.mybatis.intercept;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.xiaolong.common.context.ApplicationContext;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class FieldFillIntercept implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "crate_user_id", Long.class,ApplicationContext.getUser().getUserId());
        this.strictInsertFill(metaObject, "crate_time", LocalDateTime.class,LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "update_user_id", Long.class,ApplicationContext.getUser().getUserId());
        this.strictUpdateFill(metaObject, "update_time", LocalDateTime.class,LocalDateTime.now());
    }
}
